package com.ting.test.algorithms.recursion;

/**
 * Created by 雷霆 on 2020/3/17.
 * <p>
 * Description：
 */
public class Fib {
    public int fib(int n) {
        if (n == 1 || n == 2) {
            return 1;
        }
        return (fib(n - 1) + fib(n - 2)) % 1000000007;

    }

    public int fib2(int n) {
        if (n == 1) {
            return 1;
        }
        int fibA = 0;
        int fibB = 1;
        int temp=0;
        for (int i = 1; i < n; i++) {
            temp = fibA + fibB;
            fibA = fibB;
            fibB = temp;

        }
        return temp;


    }

    public static void main(String[] args) {
        int n = 10;
        int result = new Fib().fib2(n);
        System.out.println(result);
    }
}
